//
//  YWNewReplyTableViewCell.m
//  maintain
//
//  Created by 烟雨云渊 on 2017/5/15.
//  Copyright © 2017年 ewin. All rights reserved.
//

#import "YWNewReplyTableViewCell.h"
#import "YWCommonTool.h"
#import "YWHandler.h"
#import "YWReply.h"
#import "YWMacro.h"
#import "Masonry.h"
#import "UIColor+CustomColors.h"
#import "UIImageView+WebCache.h"
#import "YYLabel.h"

@interface YWNewReplyTableViewCell()
/** replyTag */
//@property (nonatomic, strong) YYLabel *replyTag;
/** 时间 */
//@property (nonatomic, strong) YYLabel *timeLable;
/** 评论内容 */
@property (nonatomic, strong) YYLabel *commentLabel;
@end

@implementation YWNewReplyTableViewCell
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.layer.shouldRasterize = YES;
        self.layer.rasterizationScale = [UIScreen mainScreen].scale;
        [self setUpSubviews];
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        self.separatorInset = UIEdgeInsetsMake(0, SCREEN_WIDTH, 0, 0);
    }
    return self;
}

//- (void)setReplyTagText:(NSString *)replyTagText{
//    _replyTagText = replyTagText;
//    _replyTag.text = _replyTagText;
//}

-(void)setReply:(YWReply *)reply{
    _reply = reply;

    //    时间
    NSString * timeStr = [YWCommonTool showDateAndTime:reply.replyTime/1000];
    NSString * timeText = [NSString stringWithFormat:@"  %@",timeStr];
    //    内容
    NSString *replyName = [NSString stringWithFormat:@"%@: ",reply.replier.userName];
    NSString *atUserName = reply.atUser.userName.length>0?[NSString stringWithFormat:@"@%@",reply.atUser.userName]:@"";
    NSString * content = atUserName.length?[NSString stringWithFormat:@" %@",reply.content.length>0?reply.content:@""] : (reply.content.length>0?reply.content:@"");
    _commentLabel.attributedText = [YWCommonTool attributedTextWithFirstText:replyName firstColor:[UIColor customBlueColor] firstFont:kContentFont secondText:atUserName secondColor:[UIColor customBlueColor] secFont:kContentFont thirdText:content thirdColor:[UIColor blackColor] thirdFont:kContentFont fourthText:timeText fourthColor:[UIColor customTextGrayColor] fourFont:[UIFont systemFontOfSize:13]];
    self.commentLabel.preferredMaxLayoutWidth = self.commentLabel.frame.size.width;
}

- (void)setUpSubviews{
    UIView *supView = self.contentView;
//    [self.replyTag mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.left.and.top.mas_equalTo(supView).offset(8);
//        make.width.lessThanOrEqualTo(@90);
//    }];
    
    [self.commentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(supView);
        make.left.mas_equalTo(supView).offset(8);
        make.right.mas_equalTo(supView).offset(-8);
        make.bottom.mas_equalTo(supView).offset(-6);
    }];
}

//- (YYLabel *)replyTag{
//    if (!_replyTag) {
//        YYLabel *label = [[YYLabel alloc] init];
//        label.font = kContentFont;
//        label.textColor = [UIColor customTextGrayColor];
//        _replyTag = label;
//        _replyTag.tag = 101;
//        [self.contentView addSubview:_replyTag];
//    }
//    return _replyTag;
//}

- (YYLabel *)commentLabel{
    if (!_commentLabel) {
        YYLabel *label = [[YYLabel alloc] init];
        label.textColor = [UIColor blackColor];
        label.numberOfLines = 0;
        _commentLabel = label;
        [self.contentView addSubview:_commentLabel];
    }
    return _commentLabel;
}

//- (YYLabel *)timeLable{
//    if (!_timeLable) {
//        YYLabel *label = [[YYLabel alloc] init];
//        label.font = kContentFont;
//        label.textColor = [UIColor customTextGrayColor];
//        _timeLable = label;
//        [self.contentView addSubview:_timeLable];
//    }
//    return _timeLable;
//}
@end
